package org.java2me.mobileboxing;

import java.util.Date;
import java.util.Timer;

/**
 * Created by IntelliJ IDEA.
 * User: aterreno
 */
public class Scheduler {
    private Timer timerForWork = new Timer();
    private Timer timerForPause = new Timer();
    public final static long pausePeriodMsecs = 5 * 60 * 1000;
    public final static long workingPeriodMsecs = 25 * 60 * 1000;
    public final static long totalPeriodMsecs = 30 * 60 * 1000;

    private final MobileBoxingCanvas canvas;

    public Scheduler(MobileBoxingCanvas canvas) {
        this.canvas = canvas;
    }

    public void resetTimers() {
        timerForWork.cancel();
        timerForPause.cancel();

        timerForWork = new Timer();
        timerForPause = new Timer();
    }

    public void start() {
        timerForWork.scheduleAtFixedRate(new WorkTask(canvas), new Date(), totalPeriodMsecs);
        timerForPause.scheduleAtFixedRate(new PauseTask(canvas), workingPeriodMsecs, workingPeriodMsecs);
    }
}
